﻿using System.Linq;
using CardPlay.Model.CardModel;
using CardPlay.Model.GameModel;
using CardPlay.Model.GameModel.Presentation;
using CardPlay.Model.Layout;
using CardPlay.Model.Primitives;

namespace CardPlay.DemoPack.Games.BakersDozenVariants
{
    [Game("0610071E-0756-47EF-B635-AFB8F055906F", LevelOfDifficulty.Medium, LevelOfSkill.MostlySkill, DurationOfPlay.Within5To10Minutes, Family = FamilyName)]
    public class BakersDozen : GoodMeasure
    {
        public BakersDozen()
        {
            TotalTableaus = 13;
        }

        public override ILayoutSite CreatePresentation(IPresentationContext presentation)
        {
            var root = presentation.CreateRowLayout();

            var tableau = presentation.CreateColumnLayout();
            root.Add(tableau);

            foreach (var nameList in new[] {NamesOfTableaus.Take(7), NamesOfTableaus.Skip(7)})
            {
                var tableauRow = presentation.CreateRowLayout();
                tableau.Add(tableauRow);

                tableauRow.MinimumSize = new Size(0, presentation.Metrics.CardSize.Height * 3 / 2);
                presentation.AddPiles(tableauRow, nameList, StandardStyles.Tableau);

                tableau.Add(presentation.CreateMimimalSpacer());
            }

            for (var i = 0; i < TotalFoundations / CardFace.SuitsPerDeck; ++i)
            {
                root.Add(presentation.CreateMimimalSpacer());

                var foundations = presentation.CreateColumnLayout();
                root.Add(foundations);

                presentation.AddPiles(foundations, NamesOfFoundations.Skip(i * CardFace.SuitsPerDeck).Take(CardFace.SuitsPerDeck),
                    presentation.StyleForRepeatedRankFoundation(this, FoundationBaseRank, TotalDecks));
            }

            return root;
        }

        protected override void PrepareDealScript(DealScript script)
        {
            var cardsPerTableau = TotalDecks * CardFace.CardsPerStandardDeck / TotalTableaus;
            script.DealToEach(NamesOfTableaus, cardsPerTableau + " up");
        }
    }
}